/*
 * Created by SharpDevelop.
 * Author: Joey
 * Date: 26/09/2007
 * Time: 00:08
 * 
 * Source is copyright Joey Sabey 2007
 */

using System;
using System.IO;
using System.Text;

//dictionary typedefs
using StringDic  = System.Collections.Generic.Dictionary<string,string>;
using IntDic     = System.Collections.Generic.Dictionary<string,int>;

namespace MonoTheism
{
	/// <summary>
	/// Description of Agent.
	/// </summary>
	public class AGNT_Block : Block
	{
		private string sName;
		override public string Name
		{
			get{return sName;}
		}
		private int iBioenergyValue;
		public int BioenergyValue
		{
			get{return iBioenergyValue;}
			set{iBioenergyValue = value;}
		}
		private int iAgentType = 0; //- agent suitable for injection
		public int AgentType
		{
			get{return iAgentType;}
			set{iAgentType = value;}
		}
		private string sRemoveScript;
		public string RemoveScript
		{
			get{return sRemoveScript;}
			set{sRemoveScript = value;}
		}
		private string sAnimFile;
		public string AnimFile
		{
			get{return sAnimFile;}
			set{sAnimFile = value;}
		}
		private string sAnimGallery;
		public string AnimGallery
		{
			get{return sAnimGallery;}
			set{sAnimGallery = value;}
		}
		private string sAnimString;
		public string AnimString
		{
			get{return sAnimString;}
			set{sAnimString = value;}
		}
		private String_List slScripts = new String_List();
		public String_List Scripts
		{
			get{return slScripts;}
		}
		public int ScriptCount
		{
			get{return slScripts.Count;}
		}
		private Int_List ilDependencyCategories = new Int_List();
		public Int_List DependencyCategories
		{
			get{return ilDependencyCategories;}
		}
		private String_List slDependencies = new String_List();
		public String_List Dependencies
		{
			get{return slDependencies;}
		}
		public int DependencyCount
		{
			get{return slDependencies.Count;}
		}
		
		public IntDic Ints
		{
			get
			{
				IntDic idTags = new IntDic();
				idTags.Add("Agent Bionenergy Value",
				           iBioenergyValue);
				idTags.Add("Agent Type",
				           iAgentType);
				for(int x=0; x < ilDependencyCategories.Count; x++)
				{
					idTags.Add("Dependency Category " + (x+1),
					           ilDependencyCategories[x]);
				}
				idTags.Add("Dependency Count",
				           ilDependencyCategories.Count);
				idTags.Add("Script Count",
				           slScripts.Count);
				return idTags;
			}
		}
		public StringDic Strings
		{
			get
			{
				StringDic sdTags = new StringDic();
				sdTags.Add("Agent Animation File",
				           sAnimFile);
				sdTags.Add("Agent Animation Gallery",
				           sAnimGallery);
				sdTags.Add("Agent Animation String",
				           sAnimString);
				sdTags.Add("Remove script",
				           sRemoveScript);
				for(int x=0; x < slDependencies.Count; x++)
				{
					sdTags.Add("Dependency " + (x+1),
					           slDependencies[x]);
				}
				for(int x=0; x < slScripts.Count; x++)
				{
					FileStream fsFile;
					fsFile = File.Open(slScripts[x].TrimEnd(Char.Parse("\0")),
			                 		  FileMode.Open,
			                  		  FileAccess.Read);
					byte[] buffer = new byte[fsFile.Length];
					fsFile.Read(buffer, 0, (int)fsFile.Length);
					fsFile.Close();
					sdTags.Add("Script " + (x+1),
					           Encoding.ASCII.GetString(buffer));
				}
				return sdTags;
			}
		}
		
		public AGNT_Block(string name)
		{
			sName = name;
		}
		
		public void AddScript(string sScriptFile)
		{
			slScripts.Add(sScriptFile);
		}
		
		public void AddDependency(string sDependency)
		{
			int iBuffer;
			string sFileExt = System.IO.Path.GetExtension(sDependency);
			if(sFileExt == ".wav")
				iBuffer = 1;
			else if(sFileExt == ".c16" | sFileExt == ".s16")
				iBuffer = 2;
			else if(sFileExt == ".catalogue")
				iBuffer = 7;
			else
				iBuffer = 0;
			AddDep(sDependency, iBuffer);
		}
		public void AddDependency(string sDependency, int iType)
		{
			AddDep(sDependency, iType);
		}
		
		private void AddDep(string sDependency, int iType)
		{
			slDependencies.Add(sDependency);
			ilDependencyCategories.Add(iType);
		}
		
		override public string Type()
		{
			return "AGNT";
		}
	}
}
